package org.makcro.sms.services.chat.web.client.widgets.bulk;

import org.makcro.sms.services.chat.web.shared.dto.BulkMessageDto;

import com.extjs.gxt.ui.client.core.Template;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.util.Params;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;

public class DeliveryStatusCellRendererImpl implements GridCellRenderer<BulkMessageDto> {

	private Template	template				= new Template( "<span style='color:{textColor}'>{value}</span>" );
	private String		deliveredTextColor		= "#0066FF";
	private String		undeliveredTextColor	= "#CC0000";
	private String		deliveredStatusValue	= "Da";
	private String		unDeliveredStatusValue	= "Ne";
	
	@Override
	public Object render(BulkMessageDto model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<BulkMessageDto> store, Grid<BulkMessageDto> grid) {
		Boolean messageDelivered = model.getDelivered();
		// set template param values
		Params params = new Params();
		params.set( "textColor", messageDelivered ? deliveredTextColor : undeliveredTextColor );
		params.set( "value", messageDelivered ? deliveredStatusValue: unDeliveredStatusValue);
		String appliedTemplate = template.applyTemplate( params );
		
		return appliedTemplate.toString();
		
	}

}
